package com.ccrfid.rmc6.service.business.chongqing;

import com.ccrfid.rmc6.entity.business.chongqing.CQPatrolRoadEntity;
import com.ccrfid.rmc6.service.amq.MqMsgProducer;
import com.ccrfid.rmc6.util.JsonUtil;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class CQPatrolServiceAspect {
    @Autowired
    private MqMsgProducer mqMsgProducer;

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.business.chongqing.CQPatrolService.createCQPatrolRoad(..))",
            returning = "ret")
    public void afterCreateCQPatrolRoad(CQPatrolRoadEntity ret) {
        String msg = JsonUtil.INSTANCE.writeValueAsString(ret);
        mqMsgProducer.send2Topic("ws_cq_patrol_road_create", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.business.chongqing.CQPatrolService.deleteCQPatrolRoad(..)) && args(roadId)",
            argNames = "roadId")
    public void afterDeleteCQPatrolRoad(Long roadId) {
        String msg = "[" + roadId + "]";
        mqMsgProducer.send2Topic("ws_cq_patrol_road_delete", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.business.chongqing.CQPatrolService.createCQPatrolLocation(..)) && args(roadId, locationId)",
            argNames = "roadId, locationId")
    public void afterCreateCQPatrolLocation(Long roadId, Long locationId) {
        String msg = "[" + roadId + "," + locationId + "]";
        mqMsgProducer.send2Topic("ws_cq_patrol_location_create", msg);
    }

    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.business.chongqing.CQPatrolService.deleteCQPatrolLocation(..)) && args(roadId, locationId)",
            argNames = "roadId, locationId")
    public void afterDeleteCQPatrolLocation(Long roadId, Long locationId) {
        String msg = "[" + roadId + "," + locationId + "]";
        mqMsgProducer.send2Topic("ws_cq_patrol_location_delete", msg);
    }
}
